-- vim:set ft=lua:
dofile(mg.script_name:gsub('[^\\/]*$','')..'util.lua')
if USE_LIVEJK then
dofile(mg.script_name:gsub('[^\\/]*$','')..'jkconst.lua')
end
vtag=GetVarInt(mg.request_info.query_string,'vtag') or -1
ct=CreateContentBuilder(GZIP_THRESHOLD_BYTE)
ct:Append((vtag<=0 and DOCTYPE_HTML4_STRICT or '\n')..[=[
]=]..DefaultHeadContents()..[=[
]=])
focus=nil
post=AssertPost()
if post then
focus=edcb.GetReserveData(GetVarInt(post,'del') or 0)
if focus then
edcb.DelReserveData(focus.reserveID)
ct:Append('
削除しました
\n')
end
end
edcb.htmlEscape=15
a=edcb.GetReserveData()
aComp=CompareFields('reserveID')
if not focus then
focus=GetVarInt(mg.request_info.query_string,'id')
focus=focus and BinarySearch(a,{reserveID=focus},aComp)
end
for i,v in ipairs(edcb.GetTunerReserveAll()) do
v.tunerName=v.tunerName:gsub('(.)%.[0-9A-Za-z]+$','%1')
v.tunerName=v.tunerName:sub(#v.tunerName>9 and IsEqualPath(v.tunerName:sub(1,9),'BonDriver') and 10 or 1)
for j,w in ipairs(v.reserveList) do
(BinarySearch(a,{reserveID=w},aComp) or {}).tunerName=v.tunerName
end
end
table.sort(a,function(a,b) return CompareTime(a.startTime,b.startTime) end)
pageCount=RESERVE_PAGE_COUNT
if focus then
--focusの行を含むページを探す
focusIndex=BinarySearchBound(a,focus,function(a,b) return CompareTime(a.startTime,b.startTime) end)
page=math.floor(math.max(math.min(focusIndex-1,#a-1),0)/pageCount)
else
page=GetVarInt(mg.request_info.query_string,'page',0,(#a-1)/pageCount) or 0
end
pageNav=''
if #a>pageCount then
for i=math.max(page-1,1),math.min(math.max(page-1,1)+6,(#a+pageCount-1)/pageCount) do
pageNav=pageNav..(i-1==page and ((i-1)*pageCount+1)..'~ ' or '
'..((i-1)*pageCount+1)..'~ ')
end
pageNav=(page==0 and '|<< ' or '
|<< ')..pageNav
..(page==math.floor((#a-1)/pageCount) and '>>|' or '
>>|\n')
end
ct:Append(pageNav)
ct:Append([=[
]=])
a={}
for i,v in ipairs(edcb.FindFile(SendTSTCPPipePath('*',0),0) or {}) do
n=v.name:match('^[^_]+_(%d+)_%d+')
if n then
a[#a+1]=n
end
end
if #a>0 then
n=mg.get_var(mg.request_info.query_string,'n') or a[1]
xq=GetTranscodeQueries(mg.request_info.query_string)
ct:Append('視聴 →
'..(vtag==0 and 'Video' or 'DL')..'\n'
..'
\n')
if vtag==1 then
for i,v in ipairs(a) do
if n==v then
src='view.lua?n='..v..ConstructTranscodeQueries(xq)..'&ctok='..CsrfToken('view.lua')
ct:Append(VideoWrapperBegin()
..(xq.tslive and '
' or
'
')
..VideoWrapperEnd(USE_LIVEJK and GetChatStreamNameList())..'\n'..TranscodeScriptTemplate(true,xq,{n=v}))
ct:Append('\n')
break
end
end
end
end
ct:Append([=[
]=])
ct:Finish()
mg.write(ct:Pop(Response(200,'text/html','utf-8',ct.len,ct.gzip)
..'Cross-Origin-Embedder-Policy: require-corp\r\n'
..'Cross-Origin-Opener-Policy: same-origin\r\n'
..'\r\n'))